package br.com.management.mentor.app.components.messageextractors;

import java.util.Locale;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;

import br.com.management.mentor.app.components.ExceptionMessageExtractor;
import br.com.management.mentor.app.exceptions.AppStartUpException;
import br.com.management.mentor.app.exceptions.IconImgIOException;
import br.com.management.mentor.app.exceptions.IconImgNotFoundException;

public class IconImgExceptionMessageExtractor implements ExceptionMessageExtractor {

	@Autowired
	private Locale locale;

	@Autowired
	private ApplicationContext context;

	@Override
	public boolean canHandle( Exception e ) {
		if ( e instanceof IconImgIOException )
			return true;
		if ( e instanceof IconImgNotFoundException )
			return true;
		return false;
	}

	@Override
	public String getMessage( Exception e ) {
		AppStartUpException asue = (AppStartUpException) e;
		
		String key = e.getClass().getName().replace( "Exception" , ".message" );
		return context.getMessage( key , asue.getValues() , locale );
	}

}